/**
 * BladeX Commercial License Agreement
 * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
 * <p>
 * Use of this software is governed by the Commercial License Agreement
 * obtained after purchasing a license from BladeX.
 * <p>
 * 1. This software is for development use only under a valid license
 * from BladeX.
 * <p>
 * 2. Redistribution of this software's source code to any third party
 * without a commercial license is strictly prohibited.
 * <p>
 * 3. Licensees may copyright their own code but cannot use segments
 * from this software for such purposes. Copyright of this software
 * remains with BladeX.
 * <p>
 * Using this software signifies agreement to this License, and the software
 * must not be used for illegal purposes.
 * <p>
 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
 * not liable for any claims arising from secondary or illegal development.
 * <p>
 * Author: Chill Zhuang (bladejava@qq.com)
 */
package com.xjrsoft.module.bi.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.xjrsoft.common.model.result.R;
import com.xjrsoft.module.bi.common.constant.LauncherConstant;
import com.xjrsoft.module.bi.common.tool.Condition;
import com.xjrsoft.module.bi.common.tool.Func;
import com.xjrsoft.module.bi.common.tool.Kv;
import com.xjrsoft.module.bi.common.tool.Query;
import com.xjrsoft.module.bi.pojo.entity.VisualAssets;
import com.xjrsoft.module.bi.service.IVisualAssetsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 可视化资源模块 控制器
 *
 * @author BladeX
 */
@RestController
@AllArgsConstructor
@RequestMapping(LauncherConstant.APPLICATION_VISUAL_NAME + "/assets")
@Api(value = "可视化资源模块")
public class VisualAssetsController  {

	private final IVisualAssetsService visualAssetsService;

	/**
	 * 可视化资源表 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情")
	public R detail(VisualAssets visualAssets) {
		VisualAssets detail = visualAssetsService.getOne(Condition.getQueryWrapper(visualAssets));
		return R.ok(detail);
	}

	/**
	 * 可视化资源表 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页")
	public R list(String assetsName, String assetsType, Query query) {
		IPage<VisualAssets> pages = visualAssetsService.page(Condition.getPage(query.setDescs("assets_time")),
			Condition.getQueryWrapper(Kv.create().set("assetsName", assetsName).set("assetsType", assetsType), VisualAssets.class));
		return R.ok(pages);
	}

	/**
	 * 可视化资源表 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增")
	public R save(@Valid @RequestBody VisualAssets visualAssets) {
		return R.ok(visualAssetsService.save(visualAssets));
	}

	/**
	 * 可视化资源表 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改")
	public R update(@Valid @RequestBody VisualAssets visualAssets) {
		return R.ok(visualAssetsService.updateById(visualAssets));
	}

	/**
	 * 可视化资源表 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改")
	public R submit(@Valid @RequestBody VisualAssets visualAssets) {
		return R.ok(visualAssetsService.saveOrUpdate(visualAssets));
	}

	/**
	 * 可视化资源表 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "删除")
	public R remove(@RequestParam String ids) {
		return R.ok(visualAssetsService.removeByIds(Func.toLongList(ids)));
	}

}
